<?php
/*********************************************************************
 * ADVERTISEMENT-EDIT CONTROLLER
 * 
 * Author: hthieu1110
 * Date: 12/04/2011 (generated automatically)
*********************************************************************/
require_once dirname(realpath(__FILE__))."./../../config/config.inc.php";

$advertisementId = $_REQUEST['id'];

//if the first time open the update form
if ($_POST['action'] != 'edit'){
		try{
		$advertisement = new Advertisement($advertisementId);
		
	} catch (Exception $e) {
			sessionSetVar('error', 'Unable to get the Advertisement "'.$advertisementId.'".<br/>Error : '.$e->getMessage());
			header('Location:/error.php');
			exit();
	}

//open the update form and click on update button
} else {
	//check if the data is good ?
	$isFormValid = true;
	if ($isFormValid){
		//prepare the datas
		$args = array(
			'type' => $_POST['type'],
			'title' => $_POST['title'],
			'description' => $_POST['description'],
			'price' => $_POST['price'],
			'locality' => $_POST['locality'],
		);

		//send the args to add page
		sessionSetVar('args', $args);
		sessionSetVar('id', $advertisementId);
		header('Location:/advertisement-update.php');
		exit();
	}
}

$cssNames = array("advertisement-edit");

require_once VIEW_PATH."header.inc.php";
require_once VIEW_PATH."/advertisement-edit.inc.php";
require_once VIEW_PATH."footer.inc.php";
?>